/**
 *@module main
 *@name index
 *@desc 主页模块
 *@author LiHongKun
 *@date 2020-03-26 15:03:32
 */
'use strict';

const fs = require('fs');
const queryProductList = require('../actions/product/getProductAllAction');
const saveFeedback = require('../actions/feedback/saveFeedbackAction');
module.exports = async function (ctx) {
    let param = ctx.method === 'GET' ? ctx.query : ctx.request.fields;
    let action_type = param.action_type;
    try {
        switch (action_type) {
            case 'feedback':
                ctx.body = await saveFeedback(param);
                break;
            case 'get_product_list':
                ctx.body = await queryProductList(param);
                break;
            default:
                // let result = await queryProductList(param);
                /* await ctx.render('index');*/
                let result = await queryProductList(param);
                await ctx.render('feedback', {
                    data: result.data
                });
        }
    } catch (e) {
        ctx.body = {success: false, message: e.message};
    }
};